package cn.com.recycleviewdemo;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Toast;

import com.bigkoo.convenientbanner.ConvenientBanner;
import com.bigkoo.convenientbanner.listener.OnItemClickListener;

import java.util.ArrayList;
import java.util.List;

import cn.com.recycleviewdemo.adapter.HomeAdapter;
import cn.com.recycleviewdemo.adapter.wrapper.HeaderAndFooterWrapper;
import cn.com.recycleviewdemo.decoration.ItemOffsetDecoration2;
import cn.com.recycleviewdemo.helpers.BannerHelper;

public class Main2Activity extends AppCompatActivity {

    private List<String> images = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);

        images.add("http://p3.so.qhimgs1.com/bdr/_240_/t017b3c7882e94d10c3.jpg");
        images.add("http://p2.so.qhimgs1.com/bdr/_240_/t014ff21aae39e55012.jpg");
        images.add("http://p4.so.qhimgs1.com/bdr/_240_/t01eeecd6747b6de90a.jpg");
        images.add("http://p3.so.qhimgs1.com/bdr/_240_/t01077053121e18dbb3.jpg");
        images.add("http://p0.so.qhimgs1.com/bdr/_240_/t014905f88a6e3eecbc.jpg");
        images.add("http://p3.so.qhimgs1.com/bdr/_240_/t017b3c7882e94d10c3.jpg");
        images.add("http://p2.so.qhimgs1.com/bdr/_240_/t014ff21aae39e55012.jpg");
        images.add("http://p4.so.qhimgs1.com/bdr/_240_/t01eeecd6747b6de90a.jpg");
        images.add("http://p3.so.qhimgs1.com/bdr/_240_/t01077053121e18dbb3.jpg");
        images.add("http://p0.so.qhimgs1.com/bdr/_240_/t014905f88a6e3eecbc.jpg");

        RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
        HomeAdapter adapter = new HomeAdapter(images);
        recyclerView.setLayoutManager(new GridLayoutManager(this, 2));
        ItemOffsetDecoration2 itemDecoration = new ItemOffsetDecoration2(this, R.dimen.item_offset);
        recyclerView.addItemDecoration(itemDecoration);

        HeaderAndFooterWrapper headerAndFooterWrapper = new HeaderAndFooterWrapper(adapter);
        View headreView = LayoutInflater.from(this).inflate(R.layout.header, null);
        View headreView2 = LayoutInflater.from(this).inflate(R.layout.header_2, null);
        headerAndFooterWrapper.addHeaderView(headreView);
        headerAndFooterWrapper.addHeaderView(headreView2);
        recyclerView.setAdapter(headerAndFooterWrapper);

        ConvenientBanner convenientBanner = (ConvenientBanner)headreView.findViewById(R.id.convenientBanner);
        List<String> list = new ArrayList<>();
        list.add("http://p3.so.qhimgs1.com/bdr/_240_/t017b3c7882e94d10c3.jpg");
        list.add("http://p2.so.qhimgs1.com/bdr/_240_/t014ff21aae39e55012.jpg");
        list.add("http://p4.so.qhimgs1.com/bdr/_240_/t01eeecd6747b6de90a.jpg");
        list.add("http://p3.so.qhimgs1.com/bdr/_240_/t01077053121e18dbb3.jpg");
        list.add("http://p0.so.qhimgs1.com/bdr/_240_/t014905f88a6e3eecbc.jpg");
        BannerHelper.init(convenientBanner, list, new OnItemClickListener() {
            @Override
            public void onItemClick(int position) {
                Toast.makeText(Main2Activity.this, "position:"+position, Toast.LENGTH_SHORT).show();
            }
        });
    }



}
